package ProjectTeam39.Domains;
/**
 * DoctorDay.java
 * This class represents a single doctor's appointment schedule for a single day.
 * 
 * @author SeanPohjalainen
 * @version 1.0
 */
public class DoctorDay {
	/** the data structure holding the appointments */
	private Appointment[] appts;
	/** the doctor's name */
	private String doc;
	/** the number of scheduled appointments */
	private int numAppts;
	
	/**
	 * Creates a DoctorDay object for a particular doctor.
	 * @param doctor
	 */
	public DoctorDay(String doctor){
		doc = doctor;
		numAppts = 0;
		appts = new Appointment[9];
	}
	
	/**
	 * Returns the number of scheduled appointments
	 * 
	 * @return numAppts
	 */
	public int getNumAppts(){
		return numAppts;
	}
	
	/**
	 * Returns the doctor's name
	 * 
	 * @return doc
	 */
	public String getDoctor(){
		return doc;
	}
	
	/**
	 * Set the doctor for this day.
	 * 
	 * @param doctor
	 */
	public void setDoctor(String doctor){
		doc = doctor;
	}
	
	/**
	 * Returns the appointment (or null) scheduled for the given time.
	 * 
	 * @param time
	 * @return the corresponding Appointment, or null if there isn't one.
	 */
	public Appointment searchDDAppt(int time){
			int ct; //converted time for use with array
			if (time==8){
				ct = 0;
			}
			else if (time==9){
				ct = 1;
			}
			else if (time==10){
				ct = 2;
			}
			else if (time==11){
				ct = 3;
			}
			else if (time==12){
				ct = 4;
			}
			else if (time==1){
				ct = 5;
			}
			else if (time==2){
				ct = 6;
			}
			else if (time==3){
				ct = 7;
			}
			else if (time==4){
				ct = 8;
			}
			else{
				return null;
			}
			return appts[ct];
	}
	
	/**
	 * Adds an appointment for this day.
	 * 
	 * @param appt the appointment to be scheduled
	 * @return the scheduled appointment, or null if already taken/the time is out of bounds.
	 * 
	 */
	public Appointment addAppt(Appointment appt){
		int ct; //converted time for use with array
		if (appt.getTime()==8){
			ct = 0;
		}
		else if (appt.getTime()==9){
			ct = 1;
		}
		else if (appt.getTime()==10){
			ct = 2;
		}
		else if (appt.getTime()==11){
			ct = 3;
		}
		else if (appt.getTime()==12){
			ct = 4;
		}
		else if (appt.getTime()==1){
			ct = 5;
		}
		else if (appt.getTime()==2){
			ct = 6;
		}
		else if (appt.getTime()==3){
			ct = 7;
		}
		else if (appt.getTime()==4){
			ct = 8;
		}
		else{
			return null;
		}
		if (appts[ct]!=null){
			return null;
		}
		else{
			appts[ct] = appt;
			return appt;
		}
	}
}
